package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfEmploymentEditEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
*@author 陈涛
*@date 2021/6/7
*description:
*/
public class AddCertificateAdapter extends BaseRecycleAdapter<SelfEmploymentEditEntity.NewText> {

    public IClose iClose;

    public AddCertificateAdapter(Context context, List<SelfEmploymentEditEntity.NewText> data) {
        super(context, R.layout.item_add_des, data);
    }

    @Override
    public void convert(ItemViewHolder holder, SelfEmploymentEditEntity.NewText data) {
        holder.setBinding(BR.viewModel, data);
        ImageView imgClose = holder.getItem().findViewById(R.id.img_close);
        EditText name = holder.getItem().findViewById(R.id.et_certificateName);
        View line1 = holder.getItem().findViewById(R.id.line1);
        name.setText(data.getName());
        imgClose.setOnClickListener(v -> iClose.close(holder.getLayoutPosition()));
        if (holder.getLayoutPosition() == datas.size() - 1) {
            line1.setVisibility(View.GONE);
        } else {
            line1.setVisibility(View.VISIBLE);
        }
    }

    public interface IClose {
        void close(int position);
    }

    public void setOnClose(IClose iClose) {
        this.iClose = iClose;
    }

    public void upDate() {
        notifyDataSetChanged();
    }
}
